package com.itsv.xhyy;

import java.util.ArrayList;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;

public class WenzhengMainActivity extends TabActivity implements
		OnCheckedChangeListener {
	private TabHost mHost;
	private Intent writeIntent;
	private Intent searchIntent;
	private RadioGroup radiog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.layout_wenzheng);
		init();
		initRadios();
		setupIntent();
	}

	private void init() {
		// 初始化
		this.writeIntent = new Intent(this, WriteWZMainActivity.class);

		this.searchIntent = new Intent(this, SuggestListActivity.class);
	}

	private void setupIntent() {
		this.mHost = getTabHost();
		TabHost localTabHost = this.mHost;
		localTabHost.addTab(buildTabSpec("write_tab", R.string.ani_time,
				R.drawable.write, this.writeIntent));
		localTabHost.addTab(buildTabSpec("search_tab", R.string.ani_time,
				R.drawable.search, this.searchIntent));
	}

	private void initRadios() {
		radiog = (RadioGroup) findViewById(R.id.main_radio);
		radiog.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
			}
		});
		((RadioButton) findViewById(R.id.radio_button_home))
				.setOnCheckedChangeListener(this);
		((RadioButton) findViewById(R.id.radio_button_run))
				.setOnCheckedChangeListener(this);
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.radio_button_home:
				this.mHost.setCurrentTabByTag("write_tab");
				break;
			case R.id.radio_button_run:
				this.mHost.setCurrentTabByTag("search_tab");
				break;
			}
		}
	}

	private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
			final Intent content) {
		return this.mHost
				.newTabSpec(tag)
				.setIndicator(getString(resLabel),
						getResources().getDrawable(resIcon))
				.setContent(content);
	}

}
